//
// Created by aquawius on 23-12-6.
//

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

using ptime = boost::posix_time::ptime;
using date = boost::gregorian::date;


// posix_time中有一个time_duration, 和date_duration有点相似。用来描述时间长度， date_duration用来描述日期长度。

// time_duration date_duration 共同组成了ptime(时间点)类。（可以这样理解，但是实际不是这样的）

int main(){
    // 创建ptime对象。
    ptime pt(date(2023,12,6), boost::posix_time::time_duration(5,57,10));
    cout << to_iso_extended_string(pt.date()) << " "
         << to_simple_string(pt.time_of_day()) << endl; 
    cout << boost::posix_time::to_iso_extended_string(pt) << std::endl;
    
    ptime create_time1 = boost::posix_time::time_from_string("2023-10-20 20:01:35");
    // 如果输入的时间出现错误将会引发异常， 类似"2023-10-20     20:01:35"多一个空格也不行。
    // terminate called after throwing an instance of 'boost::wrapexcept<boost::bad_lexical_cast>'
    // what() : bad lexical cast : source type value could not be interpreted as target
    cout << to_iso_extended_string(create_time1.date()) << " "
         << to_simple_string(create_time1.time_of_day())
         << endl;

    // 转换为c语言tm结构。
    std::tm c_tm = to_tm(pt);
    cout << asctime(&c_tm) << endl;

    // 使用time_iterator进行步长遍历。
    for(boost::posix_time::time_iterator t_iter(pt, boost::posix_time::seconds(10)); t_iter <= pt + boost::posix_time::hours(1); ++t_iter){
        cout << boost::posix_time::to_iso_extended_string(*t_iter) << endl;
    }

//    boost::gregorian::date_iterator
//    boost::posix_time::time_iterator


}